package com.stupro.cjlu.service;

import com.stupro.cjlu.common.vo.ResultVO;
import com.stupro.cjlu.dao.CourseDAO;
import com.stupro.cjlu.dao.TeacherDAO;
import com.stupro.cjlu.entity.Course;
import com.stupro.cjlu.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Administrator
 * @since 2021-05-10
 */
@Service
public class TeacherService extends BaseService{

    @Autowired
    private TeacherDAO teacherDAO;

    @Autowired
    private CourseDAO courseDAO;
    public ResultVO getTeacher(Integer page,String name){
        List<Teacher> list = teacherDAO.getByPage(page,name);
        for (int i = 0; i < list.size(); i++) {
            Teacher temp = list.get(i);
            temp.setTeaPwd(null);
            list.set(i,temp);
        }
        return result(list);
    }


    public ResultVO getCourse(Integer page, String teacherName, String className) {

        return result(teacherDAO.getCourserByPage(page,teacherName,className));
    }

    public ResultVO delById(int id) {
        int count = courseDAO.getCourseCountByTeacherId(id);
        if(count==0){
            return result(teacherDAO.delById(id));
        }
        else {
            return result("改老师还有课程在进行");
        }

    }

    public ResultVO update(Teacher teacher) {
        Teacher temp = teacherDAO.get(teacher.getTeaID());
        if(temp!=null){
            return result(teacherDAO.update(teacher));
        }else{
            return result("失败");
        }
    }
}
